package letcode643

import "math"

func FindMaxAverage(nums []int, k int) float64 {

	ans, tmp := math.MinInt, 0
	for right, value := range nums {
		tmp += value
		if right < k-1 {
			continue
		}
		if right > k-1 {
			out := right - k
			tmp = tmp - nums[out]
		}
		ans = max(ans, tmp)
	}
	return float64(ans) / float64(k)
}
